<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.drugqualityspecSeeStd"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="${ctx}/lib/js/html5shiv.min.js"></script>
        <script src="${ctx}/lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1> 药品采购情况</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
                <li><a href="#">监管系统</a></li>
                <li><a href="#">药品采购情况</a></li>
        </ol>
    </section>

    <section class="content">
   		<div class="box box-success">
    	         <div class="box-body">
                <div class="input">
                	<div class="textalign1">月度<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">

                      <input id="startDateMchart"  type="datetime"  data-date-fmt="yyyy-MM" class="textinput"  data-provide="datepicker"  placeholder="月度" />
                    </div>
                     <div class="textalign" >
                         <button id="selectSpec" type="button" onclick="searchMchart();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                </div>
            </div>
    	</div>
    	<div class="box box-warning">
    		<div class="box-header with-border">
    			<h3 class="box-title" id="chartTitle"><span id="spanTitle" ><fmt:formatDate value='${lastMonth}' pattern='yyyy年MM月' /></span>药品采购金额前十名</h3>
                <div class="box-tools pull-right">
                    <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                </div>
            </div>
            <div class="box-body mchart">
                <div id="mChart" style="height: 400px; width:98%; padding: 8px;"></div>
            </div>
        </div>

        <div class=" box box-success">
            <div class="box-body">
             <form  id="form" method="post">
                <div class="input">
                	<div class="textalign1" style="width: 60px;">月度<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <table style="width:100%">
                                <tr>
                                    <td style="width:50%">
                                        <input id="startDate" type="datetime" name="starttime" class="textinput" placeholder="开始月份" />
                                    </td>
                                    <td>&nbsp;-&nbsp;</td>
                                    <td style="width:50%">
                                        <input id="endDate"  type="datetime" name="endtime" class="textinput"  placeholder="结束月份" />
                                    </td>
                                </tr>
                         </table>
                    </div>
                     <div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" name="drug_name" placeholder="<spring:message code="message.listForm.tongYongMing"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
                    <div class="textalign1">药品分类<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                       	<select class="textinput" id='drugCat' name='drugCat' >
                       		<option value='' >请选择</option>
                       		<option value='1' >西药</option>
                       		<option value='2,3' >中药</option>
                       	</select>
                    </div>
                     <div class="textalign1" >
                         <button id="selectSpec1" type="button" onclick="search();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                       <div class="textalign1" style="width: 70px;">
                         <button type="button" onclick="exportExcel();" class="btn btn-success btn-sm">导 出</button>
                    </div>
                </div>
            </form>
            </div>
          </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
       <%--  <div class=" box box-warning bottongroup">
            <button type="button" onclick="window.location.href='${ctx}/anaDruginfo/toAnaByDrugsWithYear.html';" class="btn btn-primary btn-sm"><spring:message code="message.ana.year"/></button>
            <button type="button" onclick="window.location.href='${ctx}/anaDruginfo/toAnaByDrugsWithSea.html';" class="btn btn-primary btn-sm"><spring:message code="message.ana.quarter"/></button>
        </div> --%>
    </section>
    
    
      <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
		var obj ={
 			"names": [
                    '操作',
                    '月度',
                    '通用名',
                    '剂型',
                    '规格',
                    '转换系数',
                    '包装单位',
                    '生产企业',
                    '药品分类',
                    '采购总金额(万元)',
                    '配送金额(万元)',
                  	'入库金额(万元)',
                  	'配送率',
					'入库率'
                ],
	        "model": [
                    { name: 'operate', width: 140, align:"center", sortable: false,
  				 		formatter: function (val, opts, row) {
  				 			var str = "";
  				 			str+="<a href='javascript:void(0)' onclick='toAnaHospdruginfoTotal(\""+row.total_amount+"\",\""+row.del_amount+"\",\""+row.recp_amount+"\",\""+row.drug_code+"\",\""+row.drug_name+"\",\""+row.date+"\",\"mon\");'  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -20px -120px' class='opIcon' title='医院采购详情'></a>";
  				 			str+="<a href='javascript:void(0)' onclick='toAnaAreadruginfoTotal(\""+row.total_amount+"\",\""+row.del_amount+"\",\""+row.recp_amount+"\",\""+row.drug_code+"\",\""+row.drug_name+"\",\""+row.date+"\",\"mon\");'  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -20px -100px' class='opIcon' title='地区采购详情'></a>";
  				 			str+="<a href='javascript:void(0)'  onclick='toAnaDeldruginfoTotal(\""+row.total_amount+"\",\""+row.del_amount+"\",\""+row.recp_amount+"\",\""+row.drug_code+"\",\""+row.drug_name+"\",\""+row.date+"\",\"mon\");'  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px -60px' class='opIcon' title='配送企业采购详情'></a>";
  				 			//str+="<a href='javascript:void(0)' onclick='toAnaProddruginfoTotal(\""+row.total_amount+"\",\""+row.del_amount+"\",\""+row.recp_amount+"\",\""+row.drug_code+"\",\""+row.drug_name+"\",\""+row.date+"\",\"mon\");'  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -40px -120px' class='opIcon' title='生产企业采购详情'></a>";
	   				 	    return str;
	   				 	}
	   				},
                    { name: 'date', width: 120, align:"center", sortable: false},
                    { name: 'drug_name', width: 140, align:"center", sortable: false },
                    { name: 'form_name', width: 80, align:"center", sortable: false},
                    { name: 'spec_name', width: 80, align:"center", sortable: false},
                    { name: 'factor', width: 80, align:"center", sortable: false},
                    { name: 'unit_name', width: 80, align:"center", sortable: false},
                    { name: 'prod_compname', width: 180, align:"center", sortable: false},
                    { name: 'drug_cat', width: 80, align:"center", sortable: false},
                    { name: 'total_amount', width: 100, align:"center", sortable: false},
                    { name: 'del_amount', width: 100, align:"center", sortable: false},
                    { name: 'recp_amount', width: 100, align:"center", sortable: false},
                    { name: 'del_ratio', width: 100, align:"center", sortable: false},
                    { name: 'recp_ratio', width: 100, align:"center", sortable: false}


                ],  
 		};
		
        $(function () {
        	
         	 //绑定回车
            $('#startDateMchart').bind('keydown', function(event) {
                if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
                    $('#selectSpec').click();
                }
            }); 
        	 
            $('#startDate,#endDate,#drugName,#drugCat').bind('keydown', function(event) {
                if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
                    $('#selectSpec1').click();
                }
            });  
            $("#drugName").focus();
            
        	var datetime =$("form input[type='datetime']");
       	    var start = datetime.eq(0);
       	 	var end = datetime.eq(1);
       		start.on('focus',function(){
        		WdatePicker({maxDate:"#F{$dp.$D('"+end.attr("id")+"')}",dateFmt:"yyyy-MM"});
        	})
        	end.on('focus',function(){
        		WdatePicker({minDate:"#F{$dp.$D('"+start.attr("id")+"')}",dateFmt:"yyyy-MM"});
        	});

            $("#gridlist").jqGrid({
                url: "${ctx}/anaDruginfo/getAnaByDrugsWithMon.html",
                postData:{starttime:"${date}",endtime:"${date}"},
                mtype: "post",
                datatype: "json",
                autowidth: true,
                shrinkToFit:false,
                height: 310,
                colNames: obj.names,
	            colModel: obj.model,
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: false,
                viewrecords: true,
                caption: "<spring:message code="message.list.proddruginfoStdlist"/>",
                gridComplete:function(){
                    autoRNWidth("gridlist");
                },
                jsonReader: {
                	 repeatitems: false,
                    id: "qualitySpecId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
			
            loadMchart();
        });
        function toAnaHospdruginfoTotal(totalAmount,delAmount,recpAmount,drugCode,drugName,date,time){
        	var postData = {totalAmount:totalAmount,delAmount:delAmount,recpAmount:recpAmount,drugCode:drugCode,drugName:drugName,date:date,time:time};
        	$.StandardPost("${ctx}/anaDruginfo/toAnaHospdruginfoTotal.html",postData);
        }
        function toAnaAreadruginfoTotal(totalAmount,delAmount,recpAmount,drugCode,drugName,date,time){
        	var postData = {totalAmount:totalAmount,delAmount:delAmount,recpAmount:recpAmount,drugCode:drugCode,drugName:drugName,date:date,time:time};
        	$.StandardPost("${ctx}/anaDruginfo/toAnaAreadruginfoTotal.html",postData);
        }
        function toAnaDeldruginfoTotal(totalAmount,delAmount,recpAmount,drugCode,drugName,date,time){
        	var postData = {totalAmount:totalAmount,delAmount:delAmount,recpAmount:recpAmount,drugCode:drugCode,drugName:drugName,date:date,time:time};
        	$.StandardPost("${ctx}/anaDruginfo/toAnaDeldruginfoTotal.html",postData);
        }
        function toAnaProddruginfoTotal(totalAmount,delAmount,recpAmount,drugCode,drugName,date,time){
        	var postData = {totalAmount:totalAmount,delAmount:delAmount,recpAmount:recpAmount,drugCode:drugCode,drugName:drugName,date:date,time:time};
        	$.StandardPost("${ctx}/anaDruginfo/toAnaProddruginfoTotal.html",postData);
        }
        function search(page) {
        	var startDate =$("#startDate").val();
            var endDate = $.trim($("#endDate").val());
			if(endDate.length > 0 && startDate.length == 0) {
				$("#startDate").trigger("focus");
                $.alert("请选择开始月份！", "warn");
				return;
			}
        	console.log($("#form"));
        	var data =formatForm("form");
            $("#gridlist").jqGrid('setGridParam',{
                datatype:'json',
                postData:data,
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入
        }
        function searchMchart(){
          	var startMonth = $("#startDateMchart").val();
			if(startMonth.length > 0) {
				$("#spanTitle").text(startMonth.replace("-","年")+"月");
			}else {
				$("#spanTitle").text("<fmt:formatDate value='${lastMonth}' pattern='yyyy年MM月' />");
			}
			loadMchart(startMonth);
        }

        function loadMchart(startMonth){
        	postData={month:startMonth||"<fmt:formatDate value='${lastMonth}' pattern='yyyy-MM' />"};
        	$.post("${ctx}/anaDruginfo/getAnaByDrugsWithMonByMchart.html",postData,function(data){
           	option = {
         		    tooltip : {
         		        trigger: 'axis',
         		        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
         		            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
         		        }
         		    },
         		    legend: {
         		        data:[]
         		    },
         		    toolbox: {
         		        show : true,
         		        feature : {
         		            mark : {show: false},
         		            dataView : {show: false, readOnly: false},
         		            magicType : {show: false, type: ['line', 'bar', 'stack', 'tiled']},
         		            restore : {show: false},
         		            saveAsImage : {show: false}
         		        }
         		    },
         		    calculable : true,
         		    xAxis : [
         		        {
         		            type : 'value',
         		            name : '总金额(万元)'
         		        }
         		    ],
         		    yAxis : [
         		        {
         		            type : 'category',
         		            data :  eval(data.conditions.yDrug),
							axisLabel : {
								formatter: function(v){
									var drugName = (v);
									return drugName.substring(0,drugName.indexOf('/'))
								}
							}

         		        }
         		    ],
         		     series : [
         		        {
         		        	barGap:30,
         		            name:'总金额(万元)',
         		            type:'bar',
         		            data:eval(data.conditions.total)
         		        }
         		    ]
         		};
            	var myChart = echarts.init(document.getElementById('mChart'));
                myChart.setOption(option);
        	},"json");
        }
		
		
		function exportExcel(){
        	var postData =formatForm("form");
        	gridParam(postData);
        	$.StandardPost("${ctx}/anaDruginfo/exportExcelWithMon.html",postData);
        }
        var objTemp = null;
        function gridParam(postData){
        	if(!objTemp){
        		objTemp = $.extend(true, {}, obj);
        	}
        	var namesTemp = objTemp.names;
        	var modelTemp = objTemp.model;
			if($.inArray('操作',namesTemp) >= 0) {
				namesTemp.splice($.inArray('操作',namesTemp),1);
				modelTemp.splice(0,1);
			}
			var colModelStr =""; 
        	for(var mod in modelTemp){
        		colModelStr+=modelTemp[mod].name+",";
        	}
        	
			postData['colNames'] = namesTemp.toString();
        	postData['colModel'] = colModelStr.substring(0,colModelStr.length-1);		
		}
    </script>
</body>
</html>
